package buco.core.api;

import java.util.ArrayList;
import java.util.List;

public class RemoveBundleCommand extends Command<Bundle, List<SemanticMessage>> {
	
	@Override
	public List<SemanticMessage> execute() throws Exception {		 
		Bundle bundle = this.parameters; 
		List<IntegrityCheck> checks = IntegrityCheckRegistry.createIntegrityChecks();
		ArrayList<SemanticMessage> warnings = new ArrayList<SemanticMessage>();
		BundleIntegrityReport report = new BundleIntegrityReport(bundle);
		
		for(IntegrityCheck check : checks) {			
			check.bundleAdded(bundle, report);
		}
		
		warnings.addAll(report.getMessages()); 				
		
		composition.removeBundle(this.parameters);		 
		return warnings; 
	}

	@Override
	public boolean canUndo() {
		return true;
	}
	
	@Override
	public void undo() {
		try {
			composition.addBundle(this.parameters);
		} catch (DuplicateBundleException e) { 
			e.printStackTrace();
		} 
	}
}
